package com.ruoyi.project.tool.swagger.AppApi;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysCode;
import com.ruoyi.project.system.service.ISysCodeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 巡查码Controller
 *
 * @author jjp
 * @date 2020-03-30
 */
@Api("巡查码")
@RestController
@RequestMapping("/mobile/code")
public class CodeController extends BaseController {
    @Autowired
    private ISysCodeService sysCodeService;


    /**
     * 查询巡查码列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysCode sysCode) {
        startPage();
        List<SysCode> list = sysCodeService.selectSysCodeList(sysCode);
        return getDataTable(list);
    }


    /**
     * 获取巡查码详细信息
     */
    @GetMapping(value = "/{codeId}")
    public AjaxResult getInfo(@PathVariable("codeId") Long codeId) {
        return AjaxResult.success(sysCodeService.selectSysCodeById(codeId));
    }

    /**
     * 新增巡查码
     */
    @Log(title = "巡查码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysCode sysCode) {

        return toAjax(sysCodeService.insertSysCode(sysCode));
    }

    /**
     * 生成巡查码
     */
    @GetMapping("/createCodeId")
    public Long createCodeId(){
        return sysCodeService.createCodeId();
    }

    /**
     * 修改巡查码
     */
    @Log(title = "巡查码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCode sysCode) {
        return toAjax(sysCodeService.updateSysCode(sysCode));
    }

    /**
     * 删除巡查码
     */
    @Log(title = "巡查码", businessType = BusinessType.DELETE)
    @DeleteMapping("/{codeIds}")
    public AjaxResult remove(@PathVariable Long[] codeIds) {
        return toAjax(sysCodeService.deleteSysCodeByIds(codeIds));
    }
}
